// pages/write_off_cart/write_off_cart.js
const config = require('../../config.js');
const utils = require('../../utils/util.js');
const request = require('../../utils/request.js')
import { verificationConsume, getVerificationDetail } from '../../static/api/api.js'
let app = new getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        verification_code:'',
        search_ver_code:'',
        pageType:1,
        curverData:null
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    inputValueChange(e) {
        utils.inputValueChange(e, this)
    },
    verificationConsume(){
        if ((this.data.verification_code).trim()==''){
            wx.showToast({
                icon:'none',
                title: '请输入核销码'
            })
            return;
        }
        let params = {
            code: this.data.verification_code
        }
        wx.showLoading({
            title: '核销中...',
        })
        verificationConsume(params).then(response => {
            wx.hideLoading();
            console.log(response)
            wx.showToast({
                icon: 'none',
                title: '操作成功'
            })
        }).catch(response => {
            wx.hideLoading();
        })
    },
    confirmVerificationConsume(){
        let that = this;
        wx.showModal({
            title: '温馨提示',
            content: '确定要核销当前核销码吗？',
            success: function (res) {
                if (res.confirm) {
                    that.verificationConsume()

                } else if (res.cancel) {

                }

            }
        })
    },
    getVerificationDetail() {
        if ((this.data.verification_code).trim() == '') {
            wx.showToast({
                icon: 'none',
                title: '请输入要查询的核销码'
            })
            return;
        }
        let params = {
            code: this.data.verification_code
        }
        wx.showLoading({
            title: '查询中...',
        })
        getVerificationDetail(params).then(response => {
            wx.hideLoading();
            console.log(response)
            this.setData({
                curverData:response.data
            })
        }).catch(response => {
            wx.hideLoading();
        })
    },
    changeType(e){
        let dataset = e.currentTarget.dataset;
        console.log(dataset)
        this.setData({
            pageType:dataset.type
        })
    },
    goUrl(e) {
        utils.goNavigationUrl(e)
    },
})